package com.njust.RateMyTray_backend.controller;

import com.njust.RateMyTray_backend.common.Result;
import com.njust.RateMyTray_backend.service.DishService;
import com.njust.RateMyTray_backend.vo.DishDetailVO;
import com.njust.RateMyTray_backend.vo.DishVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/api/dishes")
public class DishController {

    @Autowired
    private DishService dishService;

    @GetMapping("/{dishId}")
    public ResponseEntity<Result<DishDetailVO>> getDishDetails(@PathVariable Long dishId) {
        log.info("获取菜品 {} 的详细信息", dishId);
        DishDetailVO dishDetails = dishService.getDishDetails(dishId);
        Result<DishDetailVO> result = Result.success(200, "获取菜品详情成功", dishDetails);
        return new ResponseEntity<>(result, HttpStatus.OK);
    }

    @GetMapping("/by-tag")
    public Result<List<DishVO>> getDishesByTag(@RequestParam List<String> tagNames) {
        log.info("根据标签 '{}' 查询菜品", tagNames);
        List<DishVO> dishes = dishService.getDishesByTag(tagNames);
        return Result.success(dishes);
    }
} 